﻿using System;
using System.Web.UI.WebControls;
using System.Data;
using DMS.Base;

namespace DMS.Web.Common.Controls
{
    public partial class Opinion : System.Web.UI.UserControl
    {
        private string workItem = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            workItem = Request.QueryString["workItemID"];

        }

        public string WorkItem
        {
            set
            {
                workItem = value;
            }
        }
        /// <summary>
        /// 0: 不同意； 1: 同意; -1: 未填写意见
        /// </summary>
        public int OpinionCode
        {
            get
            {
                if (this.rb_agree.Checked) return 1;                    
                if (this.rb_noagree.Checked) return 0;
                return -1;
            }
        }
        /// <summary>
        /// 保存意见
        /// </summary>
        public void Save()
        {
            if (!string.IsNullOrEmpty(workItem))
            {
                string sql = "Update WF_WorkItems SET Opinion='{0}' , OpinionDetail='{2}' WHERE wID = '{1}' ";
                string opinion = "";
                if (this.rb_agree.Checked)
                    opinion = "同意";
                if(this.rb_noagree.Checked)
                    opinion = "不同意";

                sql = string.Format(sql, opinion, workItem,this.tb_opinion.Text.Trim().Replace("'","''"));
                DBHelper.Instance.ExecuteNonQuery(CommandType.Text, sql);
            }
        }

        public void SetButtonAttribute(string key, string eventName, string script)
        {
            RadioButton opinionButton = null;
            switch (key)
            {
                case "Agree":
                    opinionButton = rb_agree;                   
                    break;

                case "DisAgree":
                    opinionButton = rb_noagree;
                    break;
                default:
                    break;
            }
            if (null != opinionButton)
                opinionButton.Attributes.Add(eventName, script);

            
        }

        public bool IsAgree;
    }
}